Skip to content

Add reputation test coverage to profile contract#49

Merged
0xdevcollins merged 1 commit into
boundlessfi:testnetfrom
Michaelkingsdev:tests/profile-reputation-coverage
Jun 25, 2026
Merged

Add reputation test coverage to profile contract#49
0xdevcollins merged 1 commit into
boundlessfi:testnetfrom
Michaelkingsdev:tests/profile-reputation-coverage

Conversation

@Michaelkingsdev

@Michaelkingsdev Michaelkingsdev commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Part of the test-coverage push (#25). This adds the reputation tests for the profile contract that #29 asks for.

What's here

tests/reputation.rs covering all three functions in the reputation module, built on the existing common.rs harness and following the admin.rs template:

  • bump — happy path, accumulation across calls, u32::MAX delta widening into u64 without overflow, zero-delta no-op, not-configured / paused / profile-not-found reverts, idempotent replay, and a no-auth rejection.
  • slash — happy path, saturating floor at zero, zero-delta no-op, the same revert set, idempotent replay, and a no-auth rejection.
  • admin_slash — happy path, saturating floor at zero, empty-reason revert, paused / profile-not-found reverts, idempotent replay, and a non-admin rejection.

No production code changed — tests plus their snapshots only.

Tests

cargo test -p boundless-profile → 24 new reputation tests pass (13 existing admin tests filtered out below):

running 24 tests
test result: ok. 24 passed; 0 failed; 0 ignored; 0 measured; 13 filtered out; finished in 0.51s

cargo test --all → green across the workspace (76 events + 37 profile, 0 failed).

Proof
image

Note on snapshots

This PR intentionally only includes the new test_snapshots/tests/reputation/ files. Re-running the suite locally also rewrites a pile of unrelated events/profile snapshots (random wasm-hash/address bytes shift between machines on the same pinned SDK), but that drift isn't part of this change so I left it out.

Closes #29

Summary by CodeRabbit

  • Tests
    • Added a comprehensive reputation contract test suite covering reputation bumps and slashes, including admin slashing behavior and key edge cases.
    • Validated correct arithmetic (including saturation at zero), zero-delta no-op behavior, and replay/idempotency guarantees.
    • Added snapshot fixtures for happy paths and failure scenarios (authorization checks, paused state, missing events contract, missing profile, and required reason handling).

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a48a4904-f6e3-425c-b2fb-14da0a353fd5

📥 Commits

Reviewing files that changed from the base of the PR and between 6e20778 and 834e6f7.

📒 Files selected for processing (26)
  • contracts/profile/src/tests/mod.rs
  • contracts/profile/src/tests/reputation.rs
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_happy_path_decrements_reputation.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_is_idempotent_on_replay.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_rejects_non_admin_caller.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_on_empty_reason.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_when_profile_not_found.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_saturates_at_zero.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_accepts_u32_max_delta_without_overflow.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_accumulates_across_calls.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_happy_path_increments_reputation.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_is_idempotent_on_replay.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_rejects_caller_without_events_contract_auth.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_events_contract_not_configured.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_profile_not_found.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_zero_delta_is_noop_but_marks_seen.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_happy_path_decrements_reputation.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_is_idempotent_on_replay.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_rejects_caller_without_events_contract_auth.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_events_contract_not_configured.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_profile_not_found.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_saturates_at_zero.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_zero_delta_is_noop.1.json
💤 Files with no reviewable changes (26)
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_when_profile_not_found.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_events_contract_not_configured.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_profile_not_found.1.json
  • contracts/profile/src/tests/mod.rs
  • contracts/profile/test_snapshots/tests/reputation/slash_rejects_caller_without_events_contract_auth.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_profile_not_found.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_on_empty_reason.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_accepts_u32_max_delta_without_overflow.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_happy_path_decrements_reputation.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_zero_delta_is_noop_but_marks_seen.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_rejects_non_admin_caller.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_events_contract_not_configured.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_zero_delta_is_noop.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_rejects_caller_without_events_contract_auth.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_saturates_at_zero.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_is_idempotent_on_replay.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_saturates_at_zero.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_is_idempotent_on_replay.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_happy_path_increments_reputation.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_accumulates_across_calls.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_is_idempotent_on_replay.1.json
  • contracts/profile/src/tests/reputation.rs
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_happy_path_decrements_reputation.1.json

📝 Walkthrough

Walkthrough

Adds a reputation test submodule to the profile contract test suite, implementing Rust tests for bump_reputation, slash_reputation, and admin_slash_reputation. Each scenario is backed by JSON ledger-state snapshots covering happy paths, edge cases, auth failures, replay handling, and pause/profile configuration states.

Changes

Reputation Test Suite

Layer / File(s) Summary
Test module registration and shared helpers
contracts/profile/src/tests/mod.rs, contracts/profile/src/tests/reputation.rs
Registers the reputation submodule and adds test helpers: random idempotency-key generation, bump/slash symbol construction, current-reputation reader, and setup_with_user bootstrapper that wires the mock events contract.
bump_reputation tests and snapshots
contracts/profile/src/tests/reputation.rs, contracts/profile/test_snapshots/tests/reputation/bump_*.json
Tests happy-path increment, accumulation across calls, max-u32 no-overflow, zero-delta no-op, missing events-contract config, paused-state, profile-not-found, idempotency replay, and auth-rejection. Each case is verified against a deterministic JSON snapshot.
slash_reputation tests and snapshots
contracts/profile/src/tests/reputation.rs, contracts/profile/test_snapshots/tests/reputation/slash_*.json
Tests happy-path decrement, saturation at zero, zero-delta no-op, missing events-contract config, paused-state, profile-not-found, idempotency replay, and auth-rejection, each with a matching JSON ledger snapshot.
admin_slash_reputation tests and snapshots
contracts/profile/src/tests/reputation.rs, contracts/profile/test_snapshots/tests/reputation/admin_slash_*.json
Tests admin-gated happy-path decrement, saturation at zero, empty-reason rejection, paused-state, profile-not-found, idempotency replay, and non-admin-caller rejection, each with a matching JSON ledger snapshot.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop, hop, the tests now sing,
Reputation bumps on a careful spring.
Slashes land, then settle low,
Replay says “seen,” and snapshots show.
Admin reason? It must be clear—
My fluffy paws approve this here!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding reputation test coverage to the profile contract.
Linked Issues check ✅ Passed The PR adds tests/reputation.rs and the module import, covering bump, slash, and admin_slash with happy paths, edge cases, auth rejection, and idempotency.
Out of Scope Changes check ✅ Passed The changes stay within the requested test-coverage work: one test module addition, a new test suite, and snapshot fixtures only.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contracts/profile/src/tests/reputation.rs`:
- Around line 181-191: In the function
bump_rejects_caller_without_events_contract_auth, replace the generic error
check assertion res.is_err() with a specific assertion that verifies the error
is the expected authorization failure variant (likely Error::Unauthorized or
Error::NotAdmin depending on what guard should trigger the failure). Apply the
same fix to the other two authorization rejection tests that use similar
patterns, ensuring each test verifies the specific error variant returned rather
than just confirming that some error occurred, which prevents false positives
from unrelated failures masking the test intent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f14cc28c-2b4a-437e-86c5-174181211289

📥 Commits

Reviewing files that changed from the base of the PR and between d3a32bd and 6e20778.

📒 Files selected for processing (26)
  • contracts/profile/src/tests/mod.rs
  • contracts/profile/src/tests/reputation.rs
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_happy_path_decrements_reputation.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_is_idempotent_on_replay.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_rejects_non_admin_caller.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_on_empty_reason.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_reverts_when_profile_not_found.1.json
  • contracts/profile/test_snapshots/tests/reputation/admin_slash_saturates_at_zero.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_accepts_u32_max_delta_without_overflow.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_accumulates_across_calls.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_happy_path_increments_reputation.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_is_idempotent_on_replay.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_rejects_caller_without_events_contract_auth.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_events_contract_not_configured.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_reverts_when_profile_not_found.1.json
  • contracts/profile/test_snapshots/tests/reputation/bump_zero_delta_is_noop_but_marks_seen.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_happy_path_decrements_reputation.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_is_idempotent_on_replay.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_rejects_caller_without_events_contract_auth.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_events_contract_not_configured.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_paused.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_reverts_when_profile_not_found.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_saturates_at_zero.1.json
  • contracts/profile/test_snapshots/tests/reputation/slash_zero_delta_is_noop.1.json

Comment on lines +181 to +191
fn bump_rejects_caller_without_events_contract_auth() {
// Genuine auth rejection: the events contract is configured, but no
// authorization is provided for the bump call, so events.require_auth()
// fails and the host aborts the invocation.
let (ctx, user) = setup_with_user();

ctx.env.mock_auths(&[]);
let res = ctx
.client
.try_bump_reputation(&user, &1, &reason(&ctx), &op_id(&ctx));
assert!(res.is_err(), "unauthorized bump must be rejected");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor

Assert specific auth-failure error variants, not just is_err().

The three auth-rejection tests (lines 181-191, 301-308, 409-419) only verify that a call fails; they do not verify it failed for the intended auth guard. This risks false positives: if any earlier guard (like require_not_paused() or a missing profile) returns an error, the test still passes.

Per the PR objectives and the pattern used throughout the rest of this test file, assert the specific Error variant returned when authorization fails (likely Error::Unauthorized or Error::NotAdmin depending on the guard).

Also applies to: 301-308, 409-419

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/profile/src/tests/reputation.rs` around lines 181 - 191, In the
function bump_rejects_caller_without_events_contract_auth, replace the generic
error check assertion res.is_err() with a specific assertion that verifies the
error is the expected authorization failure variant (likely Error::Unauthorized
or Error::NotAdmin depending on what guard should trigger the failure). Apply
the same fix to the other two authorization rejection tests that use similar
patterns, ensuring each test verifies the specific error variant returned rather
than just confirming that some error occurred, which prevents false positives
from unrelated failures masking the test intent.

@0xdevcollins

Copy link
Copy Markdown
Collaborator

@Michaelkingsdev Fix conflict

Fills in the missing tests for the reputation module: bump, slash and
admin_slash. Each one gets a happy path, every error variant it can
return, the saturating add/sub and zero-delta edges, an auth-rejection
case, and an idempotent-replay check.

No production code changed, just tests plus their snapshots.

Closes boundlessfi#29
@Michaelkingsdev Michaelkingsdev force-pushed the tests/profile-reputation-coverage branch from 6e20778 to 834e6f7 Compare June 25, 2026 11:30
@Michaelkingsdev

Copy link
Copy Markdown
Contributor Author

@Michaelkingsdev Fix conflict

Fixed

@0xdevcollins 0xdevcollins merged commit badd8d3 into boundlessfi:testnet Jun 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(profile): reputation — bump / slash / admin_slash

2 participants